package com.compass.mobile.ui.activity

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.MediaController
import com.compass.mobile.databinding.ActivityVideoPlayBinding
import com.compass.mobile.framework.base.BaseVBActivity
import com.compass.mobile.framework.constant.KEY_URL


/**
 * Description： 视频播放器
 * Date:2024/6/28 14:39
 */
class VideoPlayActivity : BaseVBActivity<ActivityVideoPlayBinding>() {

    companion object {
        fun start(context: Context, videoUrl: String?) {
            val intent = Intent(context, VideoPlayActivity::class.java)
            intent.putExtra(KEY_URL, videoUrl)
            context.startActivity(intent)
        }
    }


    private var videoUrl: String? = null
    override fun initView(savedInstanceState: Bundle?) {
        videoUrl = intent.getStringExtra(KEY_URL)
        videoUrl?.let {
            mBinding.videoView.setVideoURI(Uri.parse(it))
            mBinding.videoView.setMediaController(MediaController(this))
            mBinding.videoView.start()
            //让VideoView获取焦点
            mBinding.videoView.requestFocus()


        } ?: kotlin.run {
            showToast("视频地址异常，请联系客服")
            finish()
        }

    }

}